package org.example.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.admin.mapper.GoodsMapper;
import org.example.admin.service.GoodsService;
import org.example.entity.Goods;
import org.example.entity.GoodsAndItem;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.Date;
import java.util.List;

//@Transactional
@Service
public class GoodsServiceImpl implements GoodsService {
    private GoodsMapper goodsMapper;

    public GoodsServiceImpl(GoodsMapper goodsMapper) {
        this.goodsMapper = goodsMapper;
    }

    @Override
    public int insertGoods(Goods goods) {
        Integer counts = goodsMapper.getCounts();
        Date date = new Date();
        goods.setCreateTime(date);
        goods.setUpdateTime(date);
        goods.setGoodsId(counts+1);
        goods.setStatus("1");
        return   goodsMapper.insertGoods(goods);
    }

    public int getCounts(){
        return goodsMapper.getCounts();
    }

    @Override
    public List<GoodsAndItem> selectGoodsAll(Integer offset, Integer limit) {
        return goodsMapper.selectGoodsAll(offset, limit);
    }

    @Override
    public int getGoodsTotal() {
      return goodsMapper.getGoodsTotal();
    }

    @Override
    public int updateGoodsStatus(Integer id, Integer status) {
        return goodsMapper.updateGoodsStatus(id,status);
    }

}
